package demo.controller;

import io.github.lhdxhl.wechatpay.param.WxTransQueryParam;
import io.github.lhdxhl.wechatpay.result.WxPayInfoResult;
import io.github.lhdxhl.wechatpay.v3.WxJsPayV3Api;
import io.github.lhdxhl.wechatpay.v3.WxPayClient;
import io.github.lhdxhl.wechatpay.v3.WxResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.net.URISyntaxException;

@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private WxPayClient wxPayClient;

    @GetMapping("/queryTransByOutTradeNo")
    public String getCertificates() throws URISyntaxException, IOException {
        WxJsPayV3Api api = new WxJsPayV3Api(wxPayClient);
        WxTransQueryParam param = new WxTransQueryParam();
        param.setTransIdOrOutTradeNo("P202209281125480000002");
        WxResponseEntity<WxPayInfoResult> wxResponseEntity = api.queryTransByOutTradeNo(param);

        WxPayInfoResult body = wxResponseEntity.getBody();
        System.out.println( body.getOutTradeNo());

        return "";
    }
}
